﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


/// <summary>
/// View and modify profile values
/// </summary>
public partial class UserControls_EditUserProfile : System.Web.UI.UserControl
{
    

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// Fills the dropdown controls with the stored values
    /// of the given user.
    /// </summary>
    /// <param name="pUserName">User to show</param>
    public void ShowUsersProfile(string pUserName)
    {
        ProfileCommon profileCommon = Profile.GetProfile(pUserName);
        
        //Sex
        ddlOwnSex.SelectedValue = profileCommon.OwnSex;
        ddlPartnerSex.SelectedValue = profileCommon.ExpectedSex;
        
        //Age
        ddlOwnAge.SelectedValue = profileCommon.OwnAge;
        ddlPartnerAge.SelectedValue = profileCommon.ExpectedAge;
        
        //Build
        ddlOwnBuild.SelectedValue = profileCommon.OwnBuild;
        ddlPartnerBuild.SelectedValue = profileCommon.ExpectedBuild;
        
        //School
        ddlOwnSchool.SelectedValue = profileCommon.OwnHighestSchool;
        ddlPartnerSchool.SelectedValue = profileCommon.ExpectedHighestSchool;
    }


    /// <summary>
    /// Returns the selected values, wrapped in a ProfileEntity type
    /// </summary>
    /// <returns></returns>
    public ProfileEntity GetProfileEntity()
    {
        return new ProfileEntity
        {
            //Sex
            OwnSex = ddlOwnSex.SelectedValue,
            PartnerSex = ddlPartnerSex.SelectedValue,
            
            //Age
            OwnAge = ddlOwnAge.SelectedValue,
            PartnerAge = ddlPartnerAge.SelectedValue,
            
            //Build
            OwnBuild = ddlOwnBuild.SelectedValue,
            PartnerBuild = ddlPartnerBuild.SelectedValue,
            
            //School
            OwnHighestSchool = ddlOwnSchool.SelectedValue,
            PartnerHighestSchool = ddlPartnerSchool.SelectedValue
        };
    }

    protected void vldtrGender_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (source is DropDownList)
        {
            if (((DropDownList)source).SelectedValue == "0")
            {
                args.IsValid = false;
                
            }
        }
        
    }
}
